home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: Utrecht.NL.net!news
- From: E.H.Terwiel@inter.NL.net (E.H. Terwiel (Erik))
- Subject: Re: ** Array problem **
- X-Nntp-Posting-Host: utr98-17.utrecht.nl.net
- Message-ID: <DLI1Lo.IsM@inter.NL.net>
- Sender: news@inter.NL.net (News at newsutr)
- Organization: NLnet
- X-Newsreader: Forte Free Agent 1.0.82
- References: <4dqh8k$ov9@neptunus.pi.net>
- Date: Sat, 20 Jan 1996 21:38:44 GMT
-
- mv@pi.net wrote:
-
-
- >Hello Bill Wendlig (and everybody else),
-
-
- >A couple a days ago you replied to a message from me about some
- >problems with a piece if code..
- >You handed me some tips and corrections about a double indexed array that
- >turned out to be a 3-dimensional one..
-
- >I implemented you corrections but to no good, it made things even worse...
- >But than again I'm not a an experienced C-programmer..
-
- >But could you please tell me why this code works...
-
-
- >--------------------------------------------
-
- >#include <stdio.h>
- >#include <stdlib.h>
- >#include <string.h>
- >#include <malloc.h>
-
-
- >char *s;
- >char a[20][20];
-
-
-
- >int main (void)
-
- >{
- > int i=0;
-
- > s=(char *)malloc(18);
- > strcpy(s,"Blah blah, this works");
- > for (i=0; i<=15; i++)
- > {
- > strcpy(a[i],s);
- > }
- > for (i=0; i<=15; i++)
- > {
- > printf("%s\n",a[i]);
- > }
- > free(s);
- > return 0;
- >}
-
- >--------------------------------
-
- >This is the same situation but it works fine here ?!
-
-
- Your blabla is too long for the mallec'ed space.
- It's even too long for the 'a' arrays !
- the blabla string is 21 chars long (remember the teminating 0 ?
-
- Erik.
-
-